package cn.com.gridinfo.sooc.core.course.info.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.core.course.info.bean.CourseProcess;

/**
 * 学习进度 adapter
 * Created by yingchunli on 2016/8/19.
 */
public class ProcessAdapter extends BaseAdapter {

    private List<CourseProcess> courseProcessList;//
    private Context context;
    private int type;// 2：学习进度  1：标准

    public ProcessAdapter(List<CourseProcess> courseProcessList, Context context, int type) {
        this.courseProcessList = courseProcessList;
        this.context = context;
        this.type = type;
    }

    @Override
    public int getCount() {
        return courseProcessList.size();
    }

    @Override
    public Object getItem(int position) {
        return courseProcessList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CourseProcess courseProcess = courseProcessList.get(position);
        ViewHolder viewHolder = null;
        if (type == 1) {
            //结课标准显示
            if (convertView == null) {
                viewHolder = new ViewHolder();
                convertView = LayoutInflater.from(context).inflate(R.layout.course_stand_item, null);
                viewHolder.standIcon = (ImageView) convertView.findViewById(R.id.stand_icon);
                viewHolder.standmc = (TextView) convertView.findViewById(R.id.stand_zbmc);
                viewHolder.standtext = (TextView) convertView.findViewById(R.id.stand_zb);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            viewHolder.standtext.setText(courseProcess.getZbmrz() + courseProcess.getZbdw());
            viewHolder.standmc.setText(courseProcess.getZbmc());
            Picasso.with(context).load(courseProcess.getIcon()).resize(40, 40).into(viewHolder.standIcon);
        } else {
            //学习进度显示
            if (convertView == null) {
                viewHolder = new ViewHolder();
                convertView = LayoutInflater.from(context).inflate(R.layout.course_stand_process_item, null);
                viewHolder.processPercent = (TextView) convertView.findViewById(R.id.process_tv);
                viewHolder.progressBar = (ProgressBar) convertView.findViewById(R.id.process_pb);
                viewHolder.bzmc = (TextView) convertView.findViewById(R.id.bzmc);
                viewHolder.icon = (ImageView) convertView.findViewById(R.id.icon);

                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            Picasso.with(context).load(courseProcess.getIcon()).resize(40, 40).into(viewHolder.icon);
            viewHolder.progressBar.setProgress(Integer.parseInt(courseProcess.getProcess()));
            viewHolder.processPercent.setText(courseProcess.getProcess() + "%");
            viewHolder.bzmc.setText(courseProcess.getZbmc() + "(" + courseProcess.getNow() + courseProcess.getZbdw() + "/" + courseProcess.getZbmrz() + courseProcess.getZbdw() + ")");
        }

        return convertView;
    }

    public class ViewHolder {
        //学习进度布局
        public TextView processPercent, bzmc;//进度百分比，标准名称
        public ImageView icon;//图标
        public ProgressBar progressBar;//进度条
        //结课标准布局
        public ImageView standIcon;//图标
        public TextView standmc, standtext;//标准名称，标准内容
    }


}
